#include <stdio.h>
#include <string.h>

void Swap(char *a,char *b)
{
    char temp = *a;
    *a = *b;
    *b = temp;
}

char* reverseWords(char* s)
{
    int strat = 0;
    int end = 0;
    int pos = 0;
    char *p = s;
    while(*p != '\0')
    {
        p++;
        end++;
        if(*p == ' ' || *p == '\0')
        {
            pos = end - 1;
            while(strat < pos)
            {
                Swap(&s[strat++],&s[pos--]);
            }
            strat = end + 1;
        }
    }
    return s;
}

int main()
{
    char s[] = "hello world ni hao";
    reverseWords(s);
    printf("%s\n",s);
    return 0;
}